package hb.software.service.teacher.impl;

import hb.software.service.teacher.TeacherManager;
import hb.software.teacher.dao.TeacherDao;
import hb.software.teacher.entity.Teacher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers;
import edu.zut.hb.software.base.service.impl.GenericStudentManagerImpl;

import java.util.List;

public class TeacherManagerImpl extends GenericStudentManagerImpl<Teacher, Long> implements TeacherManager {

	TeacherDao teacherDao;

	public List<Teacher> findByName(String name) {
		// 创建查询条件数据对象
		Teacher queryObject = new Teacher();
		queryObject.setTeachername(name);
		ExampleMatcher matcher = ExampleMatcher.matching() // 构建对象
				.withMatcher("name", GenericPropertyMatchers.startsWith()) // 姓名采用“开始匹配”的方式查询
				.withIgnorePaths("dateCreated", "dateModified");
		// 创建实例并查询
		Example<Teacher> ex = Example.of(queryObject, matcher);
		List<Teacher> result = dao.findAll(ex);
		return result;
	}

	@Autowired
	public void setTeacherDao(TeacherDao teacherDao) {
		this.teacherDao = teacherDao;
		this.dao = this.teacherDao;
	}

}
